package com.jiantong.web.open.app.user;

import com.jiantong.user.model.DepartmentExtend;
import com.jiantong.user.service.DepartmentExtendReadService;
import io.terminus.boot.rpc.common.annotation.RpcConsumer;
import io.terminus.common.model.Response;
import io.terminus.pampas.openplatform.annotations.OpenBean;
import io.terminus.pampas.openplatform.annotations.OpenMethod;
import io.terminus.pampas.openplatform.exceptions.OPServerException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by mz on 12/5/17.
 *
 */
@Slf4j
@OpenBean
public class DepartmentExtendApis {

    @RpcConsumer
    private DepartmentExtendReadService departmentExtendReadService;

    @OpenMethod(
            key = "find.substation.by.factory.or.station.id",
            paramNames = {"factoryOrStationId","factoryOrPointType"},
            httpMethods = RequestMethod.GET
    )
    public String findSubstationByFactoryIdOrStation(Long factoryOrStationId,Integer factoryOrPointType){
        Response<DepartmentExtend> response = departmentExtendReadService.findByDepartmentExtend(factoryOrStationId,factoryOrPointType);
        if(!response.isSuccess()){
            log.error("failed to find department extend case = {}",response.getError());
            throw new OPServerException(response.getError());
        }
        return response.getResult().getDepartmentName();
    }
}
